<?php

$user = $_POST['user'];
$type = $_POST['type'];
$timestamp = $_POST['timestamp'];


date_default_timezone_set('Asia/Calcutta');


if($timestamp == "")
	$timestamp = time();
	
$flag = 0;
$doc = new DOMDocument();
$response = array();
$response['output'] = "";

$new_avail = 0;
$status_new = "";


  $filename1 = '../../../chat/'.$type.'.xml';

 		 $counter = 0;  
		  while($flag == 0 && $counter<60)
		  {	  

				$fhandle1 = fopen($filename1, "r");
				if($fhandle1) {
				$contents = fread($fhandle1, filesize($filename1));
				$timestampins = $contents;
					//$response["output"].=$timestampins." ";

				if((int)$timestampins > (int)$timestamp)
				 { $flag = 1; $new_avail = 1; break; }
				}

			if($flag == 1) break;			

		 // sleep for one second	  	

			$counter++;

			usleep(500000);		

	 	 }  	  

  		fclose($fhandle1);
		$time = time(); 	 	 

	$response["status"] = $status_new;
	$response["time"] = $time;

	if($new_avail==1)
		$response["new"] = "true";	
	else if($new_avail!=1)
		$response["new"] = "false";		


echo json_encode($response);

?>